package touro.finances.gui;

import java.sql.SQLException;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import touro.finances.control.ListExpensesController;
import touro.finances.model.Expense;
import touro.finances.model.FinancesDatabase;

public class ListExpenses extends JPanel{

	private JTable allExpenses;
	private Vector<String> columnHeadings;
	private Vector<Vector<Object>> data;
	private JButton refresh;
	
	public ListExpenses(FinancesDatabase fd) throws SQLException{
	
		columnHeadings = new Vector<String>();
		columnHeadings.add("ExpenseId");
		columnHeadings.add("Amount");
		columnHeadings.add("Date");
		//columnHeadings.add("Type");
		//columnHeadings.add("Location");
		columnHeadings.add("Description");
	
		data = Expense.getExpenses(fd.getConnection(), fd);
	allExpenses = new JTable(data, columnHeadings);	

	add(new JScrollPane(allExpenses));
	
	refresh = new JButton("Refresh");
	refresh.addActionListener(new ListExpensesController(fd, this));
	add(refresh);
	
	
	}
	public Vector<Vector<Object>> getData(){
		return data;
	}
	public void setData(Vector<Vector<Object>> data) {
		this.data = data;
		allExpenses.validate();
	}
	
	public void updateTable(){
		
	}
	
}
